var XPLXN_GAME_TYPE_LINE = 0;
var XPLXN_GAME_TYPE_WAYS = 1;
var CurrentGameToLoad = 0

function imageOnLoadHandler(){
	console.log(this + "cargado")
	this.gameDesc.resourcesLoadedCount++;		
}

function imageOnErrorhandler(){
	console.log(this + "no cargado")
	this.gameDesc.resourcesLoadedCount++;		
}

var XplxnControlState = {
    IDLE: 0,
    PUSHED: 1
};

function XplxnControl(){
	var posX = 0;
	var posY = 0;
	var state = XplxnControlState.IDLE
	var stateStartTime = new Date();
	var width = 0;
	var height = 0;
	var imageIndex = -1;
	var triggeredAction = function(){
	}
}

function XplxnSymbol(){	
	var imageIndex = -1;	
}

var mouseCurrentlyPressed = false;
var lastMousePressX = 0;
var lastMousePressY = 0;
var lastMousePosX = 0;
var lastMousePosY = 0;
var lastMouseDX = 0;
var lastMouseDY = 0;

function GameMousePress( X,  Y){
	mouseCurrentlyPressed = true;
	
	lastMousePosX=lastMousePressX=X;
	lastMousePosY=lastMousePressY=Y;
}

function GameMouseRelease( X,  Y){

	mouseCurrentlyPressed = false;
}

function GameMouseMove( X,  Y){
	var moveX = X-lastMousePressX;
	var moveY = Y-lastMousePressY;
	if(  (moveX*moveX+moveY*moveY)>6400 ){
		if(mouseCurrentlyPressed){
			console.log("Te has alejado 80 pix");
		}
	}

	lastMousePosX = X;
	lastMousePosY = Y;
}









function currentGameMousePressEvent(evt){
	var X;
	var Y;
	if(MSEventsInterfacePresent){
		X = evt.originalEvent.pageX;
		Y = evt.originalEvent.pageY;
	}else{
		X = evt.pageX;
		Y = evt.pageY;
	}
	var canvasRec = canvas.offset()
	cX = canvasRec.left;
	cY = canvasRec.top;	
	var actualX = (X-cX);
	var actualY = (Y-cY);
	if((actualX>=0)&&(actualX<canvas.width())){
		if((actualY>=0)&&(actualY<canvas.height())){
			GameMousePress(actualX, actualY);
		}
	}
	
}

function currentGameMouseReleaseEvent(evt){
	var X;
	var Y;
	if(MSEventsInterfacePresent){
		X = evt.originalEvent.pageX;
		Y = evt.originalEvent.pageY;
	}else{
		X = evt.pageX;
		Y = evt.pageY;
	}
	var canvasRec = canvas.offset()
	cX = canvasRec.left;
	cY = canvasRec.top;
	var actualX = (X-cX);
	var actualY = (Y-cY);
	if((actualX>=0)&&(actualX<canvas.width())){
		if((actualY>=0)&&(actualY<canvas.height())){
			GameMouseRelease(actualX, actualY);
		}
	}
}

function currentGameMouseMoveEvent(evt){
	var X;
	var Y;
	if(MSEventsInterfacePresent){
		X = evt.originalEvent.pageX;
		Y = evt.originalEvent.pageY;
	}else{
		X = evt.pageX;
		Y = evt.pageY;
	}
	var canvasRec = canvas.offset()
	cX = canvasRec.left;
	cY = canvasRec.top;
	var actualX = (X-cX);
	var actualY = (Y-cY);
	if((actualX>=0)&&(actualX<canvas.width())){
		if((actualY>=0)&&(actualY<canvas.height())){
			GameMouseMove(actualX, actualY);
		}
	}
}



var XPLXN_CONTROLS_N = 1;


function XploxionGameDesc(name){
	this.name = name
	this.index = 0;
	this.common;
	this.type = XPLXN_GAME_TYPE_LINE;
	this.nLineas = 30;
	this.maxBet = 10;
	this.nRows=3;
	this.nColums=5;
	//var BackgroundLandscape_Image;
	//var BackgroundLandscape;
	this.resourcesLoaded = false;	
	this.resourcesLoadedCount = 0;
	this.resourcesLoadedMaxCount = 1;
	this.timeInfo = new Object();
	//lista de fuentes de imagenes
	this.imageSources;
	//lista de imagenes
	this.imagesTouse;
	//Controles
	this.controls;
	//Controles
	this.simbolos;
	//Fondo
	this.backgroundImageIndex;
	this.nColumns;
	this.nRows;
	this.rowsStartSpaceX = 0.0;
	this.rowsStartSpaceY = 0.0;
	this.rowsSpaceX = 12.0;
	this.rowsSpaceY = 0.0;
	//Datos precalculados
	this.symbolsStartX = 0.0;	
	this.symbolsGridSpaceX = 0.0;
	this.symbolsDrawSizeX = 0.0;
	this.symbolsStartY = 0.0;
	this.symbolsGridSpaceY = 0.0;	
	this.symbolsDrawSizeY = 0.0;
	this.currentMatrix;//columns of rows
	this.StartShow = function(){
	  if(!this.resourcesLoaded){
		this.imagesTouse = new Array(this.resourcesLoadedMaxCount);
		this.resourcesLoadedCount = 0;
		for(var i = 0; i<this.resourcesLoadedMaxCount; i++){
			this.imagesTouse[i] = new Image();	
			this.imagesTouse[i].gameDesc = this
			this.imagesTouse[i].onload = imageOnLoadHandler
			this.imagesTouse[i].onerror = imageOnErrorhandler
			this.imagesTouse[i].src = this.imageSources[i]
		}		
	  }
	};
	
	this.preCalculateDrawingValues = function(){
		this.symbolsStartX = this.controls[1].posX+this.rowsStartSpaceX;
		var symbolsDrawSpaceX = this.controls[1].width-2*this.rowsStartSpaceX-(this.nColumns-1)*this.rowsSpaceX;
		this.symbolsDrawSizeX = symbolsDrawSpaceX/this.nColumns;
		this.symbolsGridSpaceX = this.symbolsDrawSizeX+this.rowsSpaceX;
		 
		this.symbolsStartY = this.controls[1].posY+this.rowsStartSpaceY;
		var symbolsDrawSpaceY = this.controls[1].height-2*this.rowsStartSpaceY-(this.nRows-1)*this.rowsSpaceY;
		this.symbolsDrawSizeY = symbolsDrawSpaceY/this.nRows;
		this.symbolsGridSpaceY = this.symbolsDrawSizeY+this.rowsSpaceY;
	}
	
	
	
	
	
}

 
